import java.util.concurrent.BlockingQueue;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class ExternalRetriever implements Runnable 
{
	/**
	 * The Queue to offer new Documents to.
	 */
	final BlockingQueue<Document> my_page_buffer;
	
	/**
	 * The URL String to try to make a connection on.
	 */
	final String my_url;
	
	/**
	 * Makes a new ExternalRetriever class that will attempt to connect to the
	 * given URL String and offer the code Document to the page buffer Queue.
	 * @param the_url The String URL for the connection.
	 * @param the_page_buffer The Queue for storage.
	 */
	public ExternalRetriever(final String the_url, final BlockingQueue<Document> the_page_buffer)
	{
		my_page_buffer = the_page_buffer;
		my_url = the_url;
	}
	
	/**
	 * When run will attempt to connect to the String URL given as a
	 * constructor argument and store the retrieved code Document in
	 * the Queue also given as a constructor argument.
	 */
	public void run() 
	{
		try 
		{
			final Document page = Jsoup.connect(my_url).get();
			my_page_buffer.offer(page);
		} 
		catch(final Throwable the_exception) 
		{
			//System.out.println("Bad URL: " + my_url);
		}
	}
}
